//
//  EFH5ViewController.m
//  EnjogFood
//
//  Created by guocheng on 2017/6/11.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFH5ViewController.h"

@interface EFH5ViewController ()<UIWebViewDelegate>
@property(nonatomic, copy)NSString *urlString;
@property(nonatomic, strong)UIWebView *webView;

@end

@implementation EFH5ViewController

- (instancetype)initWithUrlString:(NSString *)urlString
{
    self = [super init];
    if (self) {
        self.urlString = urlString;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.webView];
}


- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    DLog(@"webview url = %@",self.urlString);
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadTitleView{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont systemFontOfSize:17.0];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = label;
    label.text = self.title;
    [label sizeToFit];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    self.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    [self loadTitleView];
}

- (UIWebView *)webView{
    if (!_webView) {
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kStatusBarHeight)];
        _webView.delegate = self;
        _webView.scalesPageToFit = YES;
    }
    return _webView;
}

@end
